<template>
	<view class="">
		<!-- #ifdef APP-PLUS -->
		<top-set></top-set>
		<tab-top title="设置登录密码"></tab-top>
		<!-- #endif -->

		<view class="login-content">
			<view class="box">

				<!-- 输入密码 -->
				<view class="uni-form-item uni-column form-box form2">
					<view class="title">
						<image src="/static/login/password.png" mode=""></image>
					</view>
					<input v-if="!passVisible1" class="uni-input" v-model="passText1" type="text" placeholder="请输入密码" />
					<input v-if="passVisible1" class="uni-input" v-model="passText1" password type="password" placeholder="请输入密码" />

					<view :class="[passVisible1?'pass-icon-v':'pass-icon']" @tap="changePassVisible1()">
						<image :src="passVisible1?'/static/login/visual.png':'/static/login/invisible.png'" mode=""></image>
					</view>
				</view>
				<!-- 再次输入密码 -->
				<view class="uni-form-item uni-column form-box form2">
					<view class="title">
						<image src="/static/login/password.png" mode=""></image>
					</view>
					<input v-if="!passVisible2" class="uni-input" v-model="passText2" type="text" @input="passVeri()" placeholder="再次输入密码" />
					<input v-if="passVisible2" class="uni-input" v-model="passText2" password @input="passVeri()" type="password"
					 placeholder="再次入密码" />

					<view :class="[passVisible2?'pass-icon-v':'pass-icon']" @tap="changePassVisible2()">
						<image :src="passVisible2?'/static/login/visual.png':'/static/login/invisible.png'" mode=""></image>
					</view>
				</view>
				<!-- 登录按钮 -->
				<view class="uni-padding-wrap uni-common-mt">
					<button type="primary" @tap="setPass()">确定</button>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import "@/common/css/login.scss";
	let phone;
	let CryptoJS = require("crypto-js");
	export default {
		data() {
			return {
				passVisible1: true,
				passVisible2: true,
				passText1: '',
				passText2: '',
				veri: false

			}
		},
		onLoad(e) {
			phone = e.phone;
		},
		methods: {
			changePassVisible1() {
				this.passVisible1 = !this.passVisible1;
			},
			changePassVisible2() {
				this.passVisible2 = !this.passVisible2;
			},
			aes_encrypt(plainText) {
				const AES_KEY = "qq3217834abcdefg"; //16位
				const AES_IV = "1234567890123456"; //16位
				var encrypted = CryptoJS.AES.encrypt(plainText, CryptoJS.enc.Utf8.parse(AES_KEY), {
					iv: CryptoJS.enc.Utf8.parse(AES_IV)
				});
				return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
			},
			passVeri() {
				/**
				 * 判断两次输入密码是否相同
				 */
				if (this.passText1 != this.passText2 && this.passText1.length <= this.passText2.length) {
					this.veri = false;
					uni.showToast({
						title: '请确认密码'
					});
				} else {
					this.veri = true;
				}
			},
			setPass() {
				/**
				 * 确认密码
				 */
				 
				if (this.veri) {
					uni.showLoading();
					this.req({
						url: 'user/register',
						data: {
							phone: phone,
							password: this.aes_encrypt(this.passText1),
							confirmPassword: this.aes_encrypt(this.passText2)
						}
					}, (res) => {
						if(res.data.status == 1){
							console.log(res);
							uni.navigateTo({
								url: '/pages/identity/iden-selection?uid='+res.data.data.id
							});
							this.afterLogin(res.data.data);
						}else{
							uni.showToast({
								title:res.data.title
							})
						}
						uni.hideLoading();
					},(res) => {
						uni.hideLoading();
					});
					
				} else {
					uni.showToast({
						title: '请确认密码'
					});
				}
			}
		},
		mounted() {

		},
		components: {},
		computed: {

		}
	}
</script>

<style lang="scss">
	.login-content {
		box-sizing: border-box;
		width: 100%;
		padding: 19upx 102upx 0 102upx;
	}
</style>
